<html>
<head><meta charset="utf-8"><title>Playing with the new inline assembly syntax · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html">Playing with the new inline assembly syntax</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244269055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244269055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244269055">(Jun 29 2021 at 12:03)</a>:</h4>
<p>I was playing with the new syntax, and wasn't sure what's the right way to read a carry flag, so I used <code>setc</code> explictly, is this the "right" way?</p>
<p>What I was playing with: <a href="https://godbolt.org/z/ffEvE4q46">https://godbolt.org/z/ffEvE4q46</a></p>
<p>I think more complex examples with multiple asm lines, clobbers, etc might be very useful (maybe I'll try to write them myself by converting some BigInt code from C to Rust, but I'll probably find myself asking here more and more questions haha)</p>



<a name="244276064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244276064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244276064">(Jun 29 2021 at 13:00)</a>:</h4>
<p>I think so, though for <code>rdrand</code> you can also use <a href="https://doc.rust-lang.org/stable/core/arch/x86_64/fn._rdrand64_step.html"><code>core::arch::x86_64::_rdrand64_step</code></a>.</p>



<a name="244284062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244284062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244284062">(Jun 29 2021 at 13:53)</a>:</h4>
<p><code>pure</code> is incorrect here: <code>rdrand</code> reads external state, it does not depend only on its inputs.</p>



<a name="244294159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244294159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244294159">(Jun 29 2021 at 14:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax/near/244276064">said</a>:</p>
<blockquote>
<p>I think so, though for <code>rdrand</code> you can also use <a href="https://doc.rust-lang.org/stable/core/arch/x86_64/fn._rdrand64_step.html"><code>core::arch::x86_64::_rdrand64_step</code></a>.</p>
</blockquote>
<p>I know, I just thought it's a cool thing to write in asm as a start.</p>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax/near/244284062">said</a>:</p>
<blockquote>
<p><code>pure</code> is incorrect here: <code>rdrand</code> reads external state, it does not depend only on its inputs.</p>
</blockquote>
<p>Hmm, I assumed pure here will mean that if I don't use <code>rand_value</code> or <code>ok</code> then it can remove that instruction (which is true, it doesn't modify the stack or any other input).<br>
I see that it's somewhat incorrect because in practice it changes the internal RNG of the cpu, but should I care about that?</p>



<a name="244294378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244294378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244294378">(Jun 29 2021 at 14:54)</a>:</h4>
<p>Because <code>pure</code> allows the compiler to assume that the <code>asm!</code> always returns the same output given the same inputs (of which there are none).</p>



<a name="244295290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244295290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244295290">(Jun 29 2021 at 14:59)</a>:</h4>
<p>Oh, I haven't realized that, I thought it just allows it to remove the instruction if the inputs/outputs aren't used.</p>



<a name="244295680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244295680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244295680">(Jun 29 2021 at 15:01)</a>:</h4>
<p>Damn, I see the compiler actually does exactly what you said, if I call it twice it generates only a single rdrand instruction</p>



<a name="244300489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244300489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244300489">(Jun 29 2021 at 15:29)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> what would be the correct way to make an asm block without fixed output bit which can be skipped if the output value ends up not used?</p>



<a name="244310528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244310528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244310528">(Jun 29 2021 at 16:40)</a>:</h4>
<p>There isn't one.</p>



<a name="244310604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244310604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244310604">(Jun 29 2021 at 16:40)</a>:</h4>
<p>er</p>



<a name="244310614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Playing%20with%20the%20new%20inline%20assembly%20syntax/near/244310614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Playing.20with.20the.20new.20inline.20assembly.20syntax.html#244310614">(Jun 29 2021 at 16:40)</a>:</h4>
<p>Nope, there isn't one.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>